from pyglons.states import _BaseState
from pyglons import globals as g
import pyglet
from pyglet.gl import *
from pyglet.window import key


class PyglonsHelpState(_BaseState):

    def __init__(self, text):
        self._basestate.__init__(self)
        self.label = pyglet.text.HTMLLabel(text, 
            halign="center", width=10, multiline=True)
        self.on_resize(*self.window.get_size())

    def on_resize(self, width, height):
        self.label.x = width / 2
        self.label.y = height - 100
        self.label.width = width - 20
        
    def on_draw(self):
        self.clear_window()
        self.label.draw()

    def on_key_press(self, s, m):
        if self._basestate.on_key_press(self, s, m):
            return True
        if s == key.SPACE:
            g.app.pop_state()
            return True

